package com.platinadesign.axa.view
{
	import com.platinadesign.axa.event.PageTurningEvent;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class PageCorner extends Sprite
	{
		public static const CONNER_CLICKED : String = "CONNER_CLICKED";

		public static const RIGHT : String = "RIGHT";

		public static const LEFT : String = "LEFT";

		public function get direction() : String
		{
			return _direction;
		}

		private var _direction : String;

		public function PageCorner( body : Sprite, direction : String )
		{
			this.buttonMode = true;
			// body is the appearence of this class which drew in Flash.
			this.addChild( body );

			if( direction == RIGHT )
			{
				body.x = -body.width / 2;
				body.y = body.height / 2;
				_direction = RIGHT;
			}
			else if( direction == LEFT )
			{
				body.scaleX = -1;
				body.x = body.width / 2;
				body.y = body.height / 2;
				_direction = LEFT;
				body["skin"].gotoAndStop(1);
			}
			else
			{
				throw new Error( "there are only 2 kind of direction!!!!" );
				return;
			}
			initListener();
		}

		//翻一页
		protected function clickHandler( event : MouseEvent ) : void
		{
			const eventDirection : String = ( direction == LEFT ) ? PageTurningEvent.TURN_TO_RIGHT : PageTurningEvent.TURN_TO_LEFT;
			this.dispatchEvent( new PageTurningEvent( PageTurningEvent.TURN_PAGE, eventDirection ));
		}

		private function initListener() : void
		{
			//if you need other mouse behavous..add listener here..
			this.addEventListener( MouseEvent.CLICK, clickHandler );
		}
	}
}